let disp = require("../../../../utils/broadcast");
var app = getApp()
Page({
  data: {
    msgmb: 'yes',
    popshow: false,
    pingjia_cont: "",
    text_num: 0,
    hiddenmodalput: true,
    username: {
      your: "",
    },
    shouwtab: false,
    show: !0,
    hide: !1,
    xing: 0,
    evaluate: false,
    figure: 0, // 0 患者     1 医生
    dex: "", //1 处方  ！1不是
    imgs: [
      "https://img1.dxycdn.com/2020/0308/949/3400928984622785985-22.jpg",
      "https://img1.dxycdn.com/2020/0308/949/3400928984622785985-22.jpg",
      "https://img1.dxycdn.com/2020/0308/949/3400928984622785985-22.jpg",
      "https://img1.dxycdn.com/2020/0308/949/3400928984622785985-22.jpg",
    ],
    fwSuccess: "",
    upload_picture_list: [],
    typedate: 0,
    time2: '',
    play_show: true, //播放
    thtime: '00:00', //录音时长
    txt_show: true,
    recordState: false, //录音状态
    content: '', //内容
    upload_picture_list: [],
    typedate: 0,
    username: {
      your: "",
    },
    shouwtab: false,
    show: !0,
    hide: !1,
    xing: 0,
    evaluate: true,
    figure: 0, // 0 患者     1 医生
    dex: "", //1 处方  ！1不是
  },
  // 转文字
  bindzhuan(e) {
    console.log(e)
    var that = this
    var id = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    var list = that.data.list
    console.log("转文字", id)
    list[index].txt_show = false
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.shibie',
      data: {
        id: id
      },
      success: function (res) {
        console.log("文字内容", res)
        list[index].context = res.data.result[0]
        that.setData({
          list: list
        })
        console.log("文字内容", that.data.list)
      }
    })
  },


  /*** 提示*/
  tip: function (msg) {
    wx.showModal({
      title: '提示',
      content: msg,
      showCancel: false
    })
  },
  handleRecordStart: function (e) {
    console.log("开始录音", e)
    this.setData({
      is_clock: true, //长按时应设置为true，为可发送状态
      startPoint: e.touches[0], //记录触摸点的坐标信息
    })
    //设置录音参数
    const options = {
      duration: 10000,
      sampleRate: 16000,
      numberOfChannels: 1,
      encodeBitRate: 48000,
      format: 'mp3'
    }
    recorderManager.start(options); //开始录音
    wx.showToast({
      title: '录音中',
      icon: 'none',
    })
  },
  handleRecordStop: function (e) {
    console.log(app)
    var uniacid = app.siteInfo.uniacid
    recorderManager.stop() //结束录音
    //此时先判断是否需要发送录音
    if (this.data.is_clock == true) {
      //对停止录音进行监控
      var that = this
      recorderManager.onStop((res) => {
        console.log(res)
        this.setData({
          src: res.tempFilePath
        })
        var time = res.duration
        //对录音时长进行判断，少于2s的不进行发送，并做出提示
        if (res.duration < 2000) {
          wx.showToast({
            title: '录音时间太短，请长按录音',
            icon: 'none',
            duration: 1000
          })
        } else {
          var m, s;
          m = Math.floor(time / 1000 / 60 % 60);
          s = Math.floor(time / 1000 % 60);
          if (m < 10) {
            m = '0' + m
          }
          if (s < 10) {
            s = '0' + s
          }
          this.setData({
            thtime: m + ':' + s,
            endtime: time
          })
          // that.tip("录音完成！")
          //进行语音发送
          const {
            tempFilePath
          } = res;
          //上传录制的音频

          wx.uploadFile({
            url: this.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadvideo&m=hyb_yl',
            filePath: tempFilePath,
            name: 'upfile',
            success: function (res) {
              var mp3 = res.data
              var id = app.siteInfo.id
              var zid = app.siteInfo.zid
              var key_words = app.siteInfo.key_words
              if (key_words == 'tuwenwenzhen') {
                app.util.request({
                  'url': 'entry/wxapp/zhuanjia.addzhuiwen',
                  data: {
                    zid: zid,
                    id: id,
                    mp3: mp3,
                    thtime: that.data.endtime
                  },
                  success: function (res) {
                    console.log(res)
                    that.getOrderlist()
                    that.setData({
                      shouwtab: false
                    })
                    //是否提醒患者查看消息提醒
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.getmbtxing',
                      data: {
                        id: id,
                        val: '一条语音信息',
                        near: key_words
                      },
                      success: function (res) {
                        console.log(res)
                      }
                    })
                  }
                })
              }
              if (key_words == 'dianhuajizhen' || key_words == 'shipinwenzhen' || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
                app.util.request({
                  'url': 'entry/wxapp/zhuanjia.addtelzhuiwen',
                  data: {
                    zid: zid,
                    id: id,
                    key_words: key_words,
                    mp3: mp3,
                    thtime: that.data.endtime
                  },
                  success: function (res) {
                    console.log(res)
                    that.getOrderlist()
                    that.setData({
                      shouwtab: false
                    })
                    //是否提醒患者查看消息提醒
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.getmbtxing',
                      data: {
                        id: id,
                        val: '一条语音信息',
                        near: key_words
                      },
                      success: function (res) {
                        //console.log(res)
                      }
                    })
                  }
                })
              }
              if (key_words == 'yuanchengkaifang') {
                var back_orser = that.data.back_orser
                app.util.request({
                  'url': 'entry/wxapp/user.addcfzhuiwen',
                  data: {
                    zid: zid,
                    keywords: key_words,
                    role: 1,
                    orders: back_orser,
                    mp3: mp3,
                    thtime: that.data.endtime
                  },
                  success: function (res) {
                    //console.log(res)
                    that.getOrderlist()
                    that.setData({
                      shouwtab: false
                    })
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                      data: {
                        id: id,
                        val: '一条语音信息',
                        near: key_words,
                        zid: zid
                      },
                      success: function (res) {
                        //console.log(res)
                      }
                    })
                  }
                })
              }
              if (key_words == 'yuanchengguahao') {
                var back_orser = that.data.back_orser
                app.util.request({
                  'url': 'entry/wxapp/zhuanjia.addguahaozhuiwen',
                  data: {
                    val: val,
                    zid: zid,
                    id: id,
                    key_words: key_words,
                    mp3: mp3,
                    thtime: that.data.endtime
                  },
                  success: function (res) {
                    console.log(res)
                    that.getOrderlist()
                    that.setData({
                      shouwtab: false
                    })
                    //是否提醒患者查看消息提醒
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.getmbtxing',
                      data: {
                        id: id,
                        val: '一条语音信息',
                        near: key_words
                      },
                      success: function (res) {
                        //console.log(res)
                      }
                    })
                  }
                })
              }
            }
          })
        }
      })
    }
  },
  iName: function (e) {
    console.log(e)
    this.setData({
      text_num: e.detail.cursor,
      pingjia_cont: e.detail.value
    })
  },
  //查看详情  
  lookdetail() {
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/zhifuend/zhifuend?txt=yes',
    })
  },
  //立即购买   
  atbuy(e) {
    var that = this
    var c_id = e.currentTarget.dataset.c_id
    var cartlist = JSON.stringify(e.currentTarget.dataset.cartlist)
    var orders = e.currentTarget.dataset.orders
    var j_id = e.currentTarget.dataset.j_id
    var text = e.currentTarget.dataset.text
    var zhenduan = e.currentTarget.dataset.zhenduan
    var yongyao = e.currentTarget.dataset.yongyao
    var money = e.currentTarget.dataset.totals
    var ifzj = 0
    var goodsid = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/yizhu/yizhu?role=0&cartlist=' + cartlist + '&j_id=' + j_id + '&text=' + text + '&zhenduan=' + zhenduan + '&yongyao=' + yongyao + '&orders=' + orders + '&money=' + money + '&ifzj=' + ifzj + '&goodsid=' + goodsid
    })
  },

  //图片预览
  lookimg(e) {
    let url = e.currentTarget.dataset.img
    let lists = e.currentTarget.dataset.url
    var index = e.currentTarget.dataset.index
    //console.log(url, lists, index)

    let that = this;
    let src = e.currentTarget.dataset.img;
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: [src] // =============重点重点=============
    })
    // wx.previewImage({
    //   current: url,
    //   urls: lists[index].sthumb,
    // })
  },
  //关闭追问
  closezhuiwen() {
    this.setData({
      shouwtab: false
    })
  },
  clearImg: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.ind;
    console.log(index);
    var nowList = []; //新数据
    var imglis = that.data.upload_picture_list; //原数据
    imglis.splice(index, 1);
    that.setData({
      upload_picture_list: imglis
    })
  },
  //提交追问
  //提交追问
  submitformzw(e) {
    var that = this;
    var val = e.detail.value.zhuiwen;
    var upload_picture_list = that.data.upload_picture_list
    var id = that.data.id
    var zid = that.data.zid
    var typedate = that.data.typedate
    var orders = that.data.orders
    var arr = {
      'text': val,
      'typedate': typedate,
      'upload_picture_list': upload_picture_list,
    }

    app.util.request({
      'url': 'entry/wxapp/zhuanjia.adduserzhuiwen',
      data: {
        arr: arr,
        orders: orders,
        zid: zid
      },
      success: function (res) {
        console.log(res)
        that.getuserone()
        that.getOrderlook
        that.setData({
          shouwtab: false
        })
        //提醒医生
        app.util.request({
          'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
          data: {
            id: id,
            val: val,
            near: '图文',
            zid: zid
          },
          success: function (res) {
            console.log(res)
          }
        })
        app.util.request({
          'url': 'entry/wxapp/tuwen.detail',
          data: {
            orders: orders,
            openid: wx.getStorageSync('openid')
          },
          success: function (res) {
            console.log(res)
            that.setData({
              detail: res.data,
              addnum: parseInt(res.data.addnum),
              ifpay: res.data.ifpay
            })
          }
        })
      }
    })
  },
  //图片上传
  //图片上传
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;
    wx.chooseImage({
      count: 5,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr,
                typedate: 1
              })
            }
          })
        }
      }
    })
  },
  // 关闭评价
  closeevaluate() {
    this.setData({
      evaluate: false
    })
  },

  //取消按钮  
  cancelM: function (e) {
    console.log(e)
    this.setData({
      hiddenmodalput: true
    });
  },
  //确认  
  confirmM: function (e) {
    var that = this
    var xing = that.data.xing
    var content = that.data.pingjia_cont
    var zid = that.data.zid
    var orders = that.data.orders
    var key_words = 'tuwenwenzhen'
    var j_id = that.data.j_id
    wx.showModal({
      title: '评价医生',
      content: '是否提交评价',
      success(res) {
        if (res.confirm) {
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.addpingjia',
            data: {
              starsnum: xing,
              zid: zid,
              orders: orders,
              keywords: key_words,
              j_id: j_id,
              openid: wx.getStorageSync('openid'),
              content: content
            },
            success: function () {
              console.log(res)
              wx.showToast({
                title: '评价成功',
                icon: 'none'
              })
              that.setData({
                hiddenmodalput: true,
                evaluate: false
              })
            }
          })
        }
      }
    })
  },
  // 评分
  xingclick(e) {
    var that = this
    let num = that.data.xing
    var zid = that.data.zid
    var key_words = that.data.key_words
    var orders = that.data.orders
    var j_id = that.data.j_id
    if (e.currentTarget.dataset.type == 'a') {
      that.setData({
        xing: e.currentTarget.dataset.num
      })
    } else {
      that.setData({
        xing: e.currentTarget.dataset.num + num
      })
    }
    console.log(that.data.xing)
    this.setData({
      hiddenmodalput: !this.data.hiddenmodalput
    })



  },
  // 发布提问
  submitform(e) {
    let vals = e.detail.value.liuyan;
  },

  onLoad(options) {
    wx.hideNavigationBarLoading()
    var that = this
    var key_words = options.key_words
    var list = JSON.parse(options.list)
    var orders = list.orders
    var zid = list.zid
    var j_id = list.j_id
    console.log(j_id)
    var money = options.money
    var currentData = options.currentData
    //获取订阅消息id
    if (options.txt) {
      this.setData({
        txt: options.txt,
        popshow: options.txt == 'yes' ? true : false
      })
    }
    app.util.request({
      'url': 'entry/wxapp/index.techen',
      success: function (res) {
        console.log(res)
        var msg = res.data.wxapp_mb
        that.setData({
          submitOrder: msg.submitOrder, //就诊提醒
          OpenHalfcard: msg.OpenHalfcard, //用药提醒提醒
          Mobile: msg.Mobile, //问诊提醒（提醒患者，提醒医生通用）
          hexiao: msg.hexiao, //问诊状态提醒退款不接诊等等
          cfoverfcard: msg.cfoverfcard, //接种提醒
          fwSuccess: msg.fwSuccess //  服务结束提醒
        })
      }
    })

    app.util.request({
      'url': 'entry/wxapp/user.detail',
      data: {
        j_id: j_id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          usedetail: res.data
        })
      }
    })

    if (options.ifpay) {
      var ifpay = options.ifpay
      that.setData({
        ifpay: ifpay
      })
    }

    //查询订单是否评价
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.orderpj',
      data: {
        orders: orders,
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        console.log(res)
        if (res.data == 1) {
          that.setData({
            evaluate: true
          })
        } else {
          that.setData({
            evaluate: false
          })
        }

      }
    })

    //查询是否公开
    app.util.request({
      'url': 'entry/wxapp/user.answeropen',
      data: {
        orders: orders
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
          that.setData({
            open: 1
          })
        }
        if (res.data.status == 0) {
          that.setData({
            open: 0
          })
        }
        if (!res) {
          that.setData({
            open: 0
          })
        }
        that.setData({
          id: res.data.id
        })
      }
    })
    that.setData({
      orders: orders,
      zid: zid,
      key_words: key_words,
      back_orser: orders,
      money: money,
      currentData: currentData
    });
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    wx.setNavigationBarTitle({
      title: list.z_name
    });
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data,
        })
      }
    })
    that.innerAudioContext = wx.createInnerAudioContext();
  },
  onShow: function (e) {
    var that = this
    that.getOrderlook()
    that.getuserone()
    var orders = that.data.back_orser
    console.log(orders)
    app.util.request({
      'url': 'entry/wxapp/tuwen.detail',
      data: {
        orders: orders,
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        console.log(res)
        that.setData({
          detail: res.data,
          addnum: parseInt(res.data.addnum),
          ifpay: res.data.ifpay
        })
      }
    })
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.chufangcont',
      data: {
        back_orser: orders,
        c_id: 0
      },
      success: function (res) {
        console.log(res)
        that.setData({
          cfdata: res.data
        })
      }
    })
  },
  onHide() {
    var that = this
    clearInterval(that.data.time2)

  },
  onUnload() {

    clearInterval(this.data.time2)
    var currentData = this.data.currentData
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({
      currentData: currentData
    })
    disp.fire("em.chatroom.leave");
  },
  onPullDownRefresh: function () {
    wx.hideNavigationBarLoading()
    wx.showNavigationBarLoading();
    this.selectComponent('#chat').getMore()
    // 停止下拉动作
    wx.hideNavigationBarLoading();
    wx.stopPullDownRefresh();
  },
  //查询患者问诊
  getuserone() {
    var that = this
    var orders = that.data.orders
    app.util.request({
      'url': 'entry/wxapp/tuwen.listall',
      data: {
        openid: wx.getStorageSync('openid'),
        back_orser: orders,
        zid: that.data.zid
      },
      success: function (res) {
        var list = res.data
        for (var i = 0; i < list.length; i++) {
          var m, s;
          m = Math.floor(list[i].thtime / 1000 / 60 % 60);
          s = Math.floor(list[i].thtime / 1000 % 60);
          if (m < 10) {
            m = '0' + m
          }
          if (s < 10) {
            s = '0' + s
          }
          list[i].endtime = m + ':' + s
          list[i].play_show = true
          list[i].txt_show = true
          list[i].context = ''
        }
        that.setData({
          list: res.data,
        })
      }
    })
  },
  clickshow: function (t) {
    this.setData({
      show: !0,
      hide: !1
    });
  },
  clickshow1: function (t) {
    this.setData({
      show: !1,
      hide: !0
    });
  },
  //
  tabinput(e) {
    var that = this
    var back_orser = that.data.orders
    var zid = that.data.zid
    var id = that.data.detail.id
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/edit/edit?back_orser=' + back_orser + '&zid=' + zid + '&id=' + id,
    })
    // this.setData({
    //   shouwtab: !this.data.shouwtab
    // })
  },
  buttonclick: function (e) {
    var that = this
    var back_orser = that.data.back_orser
    var key_words = that.data.key_words
    var open = e.currentTarget.dataset.open
    var id = e.currentTarget.dataset.id
    console.log(back_orser, key_words, id)
    var ifpay = that.data.ifpay
    if (ifpay == 0 || ifpay == 1 || ifpay == 8 || ifpay == 2) {
      if (open == 1) {
        var msg = '取消公开'
      }
      var itemList = ['删除订单'];
    } else {
      if (open == 1) {
        var msg = '取消公开'
      } else {
        var msg = '公开问题'
      }
      var itemList = ['删除订单', msg];
    }

    wx: wx.showActionSheet({
      itemList: itemList,
      itemColor: '',
      success: function (res) {
        if (res.tapIndex == 0) {
          if (!res.cancel) {
            wx.showModal({
              title: '是否删除订单？',
              content: '删除后不可恢复',
              success: (result) => {
                if (result.confirm) {
                  app.util.request({
                    'url': 'entry/wxapp/user.delwzorder_two',
                    data: {
                      back_orser: back_orser
                    },
                    success: function (res) {
                      console.log(res)
                      wx.showToast({
                        title: '删除成功',
                        icon: 'none',
                        success: (res) => {
                          setTimeout(function () {
                            wx.navigateBack({
                              detail: 1
                            })
                          }, 2000)
                        },
                      })
                    }

                  })

                }
              },
            })
          }
        } else {
          //公开问题
          if (that.data.open == 1) {
            app.util.request({
              'url': 'enter/wxapp/user.openquestion',
              data: {
                back_orser: back_orser,
                key_words: key_words,
                id: id
              },
              success: function (res) {
                console.log(res)
                //查询是否有当前订单的公开问题
                app.util.request({
                  'url': 'entry/wxapp/user.answeropen',
                  data: {
                    orders: back_orser
                  },
                  success: function (res) {
                    console.log(res)
                    if (res.data.status == 1) {
                      that.setData({
                        open: 1,
                        id: res.data.id,
                        status: res.data.status
                      })
                    } else {
                      that.setData({
                        open: 0,
                      })
                    }
                  }
                })
              }
            })
          } else {
            wx.showModal({
              title: '是否公开问题？',
              content: '公开问题帮助更多人',
              success: function (res) {
                console.log(res)
                if (res.confirm) {
                  app.util.request({
                    'url': 'enter/wxapp/user.openquestion',
                    data: {
                      back_orser: back_orser,
                      key_words: key_words,
                      id: id
                    },
                    success: function (res) {
                      console.log(res)
                      //查询是否有当前订单的公开问题
                      app.util.request({
                        'url': 'entry/wxapp/user.answeropen',
                        data: {
                          orders: back_orser
                        },
                        success: function (res) {
                          console.log(res)
                          if (res.data.status == 1) {
                            that.setData({
                              open: 1,
                              id: res.data.id,
                              status: res.data.status
                            })
                          } else {
                            that.setData({
                              open: 0,
                            })
                          }
                        }
                      })
                    }
                  })
                }
              }
            })
          }

        }

      },
      fail: function (res) {},
      complete: function (res) {},
    })
  },
  tabinputpay() {
    var that = this
    var back_orser = that.data.back_orser
    var money = that.data.money
    var key_words = that.data.key_words
    var zid = that.data.zid
    console.log(back_orser, money, key_words, zid)
    app.util.request({
      'url': 'entry/wxapp/yuyue.paywenzhen',
      header: {
        "Content-Type": "application/xml"
      },
      method: "GET",
      data: {
        openid: wx.getStorageSync('openid'),
        z_tw_money: money,
        orders: back_orser,
        key_words: key_words
      },
      success: function (res) {
        console.log(res);
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr, //字符串随机数
          'package': res.data.package,
          'signType': res.data.signType,
          'paySign': res.data.paySign,
          success: function (res) {
            console.log(res)
            that.getuserone()
            //查询订单追问次数

            app.util.request({
              'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
              data: {
                val: '图文订单提醒',
                near: '图文问诊',
                zid: zid
              },
              success: function (res) {
                console.log(res)
              }
            })
          },
          fail: function (res) {
            console.log(res)

          }
        })
      }
    })
  },
  sqchufang(e) {
    var that = this
    var j_id = that.data.j_id
    var back_orser = that.data.back_orser
    var key_words = that.data.key_words
    var zid = that.data.zid
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/chufangmes/chufangmes?tit=远程开方&key_words=yuanchengkaifang' + '&back_orser=' + back_orser + '&zid=' + zid + '&j_id=' + j_id,
    })
  },
  tabtwoinput() {
    var that = this
    var that = this
    wx.reLaunch({
      url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid=' + that.data.zid,
    })
  },
  tuikuan(e) {
    console.log(e)
    var that = this
    var back_orser = that.data.orders
    var money = that.data.money
    console.log(money)
    if (money == '0.00') {
      var title = "是否取消问诊"
      var f_title = "取消成功"
    } else {
      var title = "是否申请退款"
      var f_title = "申请成功，请耐心等待退款"
    }
    wx.showModal({
      title: title,
      success(res) {
        if (res.confirm) {
          app.util.request({
            'url': 'entry/wxapp/user.twtuikuan',
            data: {
              back_orser: back_orser,
              money: money,
              keywords: that.data.key_words
            },
            success: function (res) {
              //消息通知
              console.log(res)
              app.util.request({
                'url': 'entry/wxapp/zhuanjia.tktemplet',
                data: {
                  orders: back_orser,
                  money: money,
                  keywords: that.data.key_words
                },
                success: function (res) {
                  console.log(res)
                }
              })
              console.log(res)
              wx.showToast({
                title: f_title,
                icon: 'none',
                success: function (res) {
                  console.log(res)
                  wx.navigateBack({
                    detail: 1
                  })
                }
              })
            }
          })
        }
      }
    })
  },
  previewImg: function (t) {
    console.log(t)
    var current = t.target.dataset.src;
    //预览图片
    var imgs = []
    imgs.push(current)
    wx.previewImage({
      current: current,
      urls: imgs,
    });
  },
  getOrderlook() {
    wx.hideNavigationBarLoading()
    var that = this
    var orders = that.data.orders
    var ifpay = that.data.ifpay
    var key_words = that.data.key_words
    //查询当前订单的可追问次数和状态
    app.util.request({
      'url': 'entry/wxapp/tuwen.detail',
      data: {
        orders: orders,
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        console.log(res)
        if (ifpay == 0 || ifpay == 1 || ifpay == 2) {
          that.data.time2 = setInterval(function () {
            that.getdetaillook()
            that.getuserone()
          }, 1000)
        }
        that.setData({
          detail: res.data,
          addnum: parseInt(res.data.addnum),
          j_id: res.data.j_id,
          ifgb: res.data.ifgb,
        })
        wx.hideNavigationBarLoading()
      }
    })
  },
  getdetaillook() {
    wx.hideNavigationBarLoading()
    var that = this
    var orders = that.data.orders
    var ifpay = that.data.ifpay
    var key_words = that.data.key_words
    var money = that.data.money;
    var tkid = app.globalData.tkid //一级
    var mytkid = app.globalData.mytkid //二级
    var ziji = app.globalData.ziji //查询当前是不是自己是一级分销商
    //查询当前订单的可追问次数和状态
    app.util.request({
      'url': 'entry/wxapp/tuwen.detail',
      data: {
        orders: orders,
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        var overtime = parseInt(res.data.overtime * 1000)
        var date1 = new Date(overtime)
        var date = new Date()
        var sheyuTime = Date.parse(date1) - Date.parse(date)
        let hours = parseInt((sheyuTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        let minutes = parseInt((sheyuTime % (1000 * 60 * 60)) / (1000 * 60));
        let seconds = (sheyuTime % (1000 * 60)) / 1000;
        that.setData({
          dumiao: hours + ":" + minutes + ":" + seconds,
          ifpay: res.data.ifpay
        })
        if (sheyuTime == 0) {
          clearInterval(that.data.time2)
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.dopagetime',
            data: {
              orders: orders,
              ifpay: ifpay,
              key_words: key_words,
            },
            success: function (res) {
              console.log(res)
              if (that.data.ifpay == '2') {
                if (ziji == 0) {
                  app.util.request({
                    'url': 'entry/wxapp/tuike.uptopmoney',
                    data: {
                      tkid: tkid,
                      mytkid: mytkid,
                      money: money,
                      openid: wx.getStorageSync('openid'),
                      leixing: key_words,
                      orders: orders
                    },
                    success: function (res) {
                      console.log(res)
                    }
                  })
                }
                app.util.request({
                  'url': 'entry/wxapp/yuyue.fanlis',
                  data: {
                    back_orser: that.data.orders,
                    keywords: that.data.key_words,
                    openid: wx.getStorageSync('openid')
                  },
                  success: function (res) {
                    console.log(res)

                  }
                })
              }
              app.util.request({
                'url': 'entry/wxapp/yuyue.upchufangwentype',
                data: {
                  orders: orders,
                },
                success: function (res) {
                  console.log(res)

                }
              })
              wx.showToast({
                title: '订单已结束',
                icon: 'none',
                success: function () {
                  setTimeout(function () {
                    wx.navigateBack({
                      detail: 1
                    }, 1500)
                  })
                }
              })

            }
          })
          return false
        }
        if (sheyuTime <= 0) {
          clearInterval(that.data.time2)
          that.setData({
            dumiao: "00:00:00"
          })
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.dopagetime',
            data: {
              orders: orders,
              ifpay: ifpay,
              key_words: key_words,
            },
            success: function (res) {
              //console.log(res)
            }
          })
        }
        that.setData({
          detail: res.data,
          addnum: parseInt(res.data.addnum),
          j_id: res.data.j_id,
          ifgb: res.data.ifgb
        })
        wx.hideNavigationBarLoading()
      }
    })
  },
  // 调取申请
  ptiontitbtn(e) {
    console.log(e)
    var that = this
    /**
     *        submitOrder: msg.submitOrder, //就诊提醒
              OpenHalfcard: msg.OpenHalfcard, //用药提醒提醒
              Mobile: msg.Mobile, //问诊提醒（提醒患者，提醒医生通用）
              hexiao: msg.hexiao, //问诊状态提醒退款不接诊等等
              settled: msg.cfoverfcard//接种提醒
     */
    var submitOrder = that.data.submitOrder
    var OpenHalfcard = that.data.OpenHalfcard
    var Mobile = that.data.Mobile
    var fwSuccess = that.data.fwSuccess;
    var hexiao = that.data.hexiao
    var cfoverfcard = that.data.cfoverfcard

    wx.requestSubscribeMessage({
      tmplIds: [submitOrder, OpenHalfcard, Mobile, fwSuccess],
      success: (res) => {
        console.log(res)
        //调用授权
      }
    })
    this.setData({
      applyFor: true,
      msgmb: 'non',
      popshow: false
    })
  },
  /*** 播放录音*/
  playRecord: function (e) {
    var that = this;
    var src = e.currentTarget.dataset.src
    var thtime = e.currentTarget.dataset.thtime
    var index = e.currentTarget.dataset.index
    var list = that.data.list
    if (src == '' || src == undefined) {
      that.tip("请先录音！")
      return;
    } else {
      that.innerAudioContext.src = e.currentTarget.dataset.src;
      that.innerAudioContext.play()

      list[index].play_show = false
      that.setData({
        list: list
      })
    }
    setInterval(function () {
      list[index].play_show = true
      that.setData({
        list: list
      })
      clearInterval()
    }, thtime)
  },
});